package com.yicong.ants.manager;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;

import com.cchao.simplelib.core.Logs;
import com.cchao.simplelib.core.RxHelper;
import com.cchao.simplelib.core.UiHelper;
import com.yicong.ants.bean.global.VersionBean;
import com.yicong.ants.manager.http.RetrofitHelper;
import com.yicong.ants.utils.AppUtils;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static com.cchao.simplelib.core.UiHelper.showToast;

/**
 * @author cchao
 * @version 2019-10-15.
 */
public class AppUpdateManager {

    public static void checkVersion2(Activity activity, boolean showTips, VersionBean versionBean) {

        if (activity.isDestroyed() || activity.isFinishing()) {
            return;
        }
        if (versionBean == null) {
            return;
        }

        if (versionBean.getUpdate() != 1) {
            if (showTips) {
                showToast(versionBean.getExplain());
            }
            return;
        }

        if (AppUpdatePopupWindow.isDownloading) {
            UiHelper.showToast("正在下载中");
            return;
        }

        AppUpdatePopupWindow mAppUpdatePop = new AppUpdatePopupWindow(activity, versionBean);
        mAppUpdatePop.setAnimationStyle(-1);
        activity.getWindow().getDecorView().post(new Runnable() {
            @Override
            public void run() {
                mAppUpdatePop.showAtLocation(activity.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
            }
        });
    }
}
